//
//  MyFriendTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/4/7.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "MyFriendTableViewCell.h"

@interface MyFriendTableViewCell ()

@property (nonatomic, strong) NSMutableArray *myMarkArray; // 标签数组

@end

@implementation MyFriendTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 构建视图
- (void)addMySubview
{
    // 用户头像
    self.friendImageV = [[UIImageView alloc] initWithFrame:CGRectMake(16 * kAdjustParamater, 18 * kAdjustParamater, 40 * kAdjustParamater, 40 * kAdjustParamater)];
    self.friendImageV.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.friendImageV.layer.cornerRadius = self.friendImageV.width / 2;
    self.friendImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_friendImageV];
    
    // 姓名
    self.xingMingLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.friendImageV.right + 7 * kAdjustParamater, 13 * kAdjustParamater, 25 * kAdjustParamater, 11 * kAdjustParamater)];
    //  self.xingMingLabel.backgroundColor = [UIColor redColor];
    self.xingMingLabel.text = @"姓名";
    self.xingMingLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    [self.contentView addSubview:_xingMingLabel];
    
    // 名字
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xingMingLabel.right + 6 * kAdjustParamater, self.xingMingLabel.top, 50 * kAdjustParamater, 11 * kAdjustParamater)];
    //   self.nameLabel.backgroundColor = [UIColor redColor];
    self.nameLabel.text = @"我叫盖伦盖伦123";
    //    [self.nameLabel sizeToFit];
    //    self.nameLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y, self.nameLabel.frame.size.width, 11 * kAdjustParamater);
    self.nameLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    [self.contentView addSubview:_nameLabel];
    
    // 性别图片
    self.genderImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.nameLabel.right + 8 * kAdjustParamater, self.nameLabel.top + 1 * kAdjustParamater, 13 * kAdjustParamater, 13 * kAdjustParamater)];
    //    self.genderImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_genderImageView];
    
    
    //    // 标签
    //    for (int i = 0; i < self.myMarkArray.count; i++) {
    //
    //        // 进行标签的动态布局
    //        UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xingMingLabel.left + tempX + 5 * kAdjustParamater, self.xingMingLabel.bottom + 4 * kAdjustParamater, 50, 19 * kAdjustParamater)];
    //        // 取出内容
    //        tempLabel.text = self.myMarkArray[i];
    //        [tempLabel sizeToFit];
    //        tempLabel.frame = CGRectMake(tempLabel.frame.origin.x, tempLabel.frame.origin.y, tempLabel.frame.size.width, 19 * kAdjustParamater);
    //        tempX = tempLabel.frame.size.width;
    //        // 添加边框
    //        [tempLabel.layer setBorderWidth:1];
    //        tempLabel.layer.borderColor = [[UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1] CGColor];
    //        [self.contentView addSubview:tempLabel];
    //    }
    
    // 账号
    self.zhaoHaoLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xingMingLabel.left, self.xingMingLabel.bottom + 30 * kAdjustParamater, 30 * kAdjustParamater, 11 * kAdjustParamater)];
    //   self.zhaoHaoLabel.backgroundColor = [UIColor redColor];
    self.zhaoHaoLabel.text = @"账号:";
    self.zhaoHaoLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    self.zhaoHaoLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
    [self.contentView addSubview:_zhaoHaoLabel];
    
    // ID
    self.IDLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.zhaoHaoLabel.right + 6 * kAdjustParamater, self.zhaoHaoLabel.top, 100 * kAdjustParamater, 11 * kAdjustParamater)];
    // self.IDLabel.backgroundColor = [UIColor redColor];
    self.IDLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    self.IDLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
    self.IDLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_IDLabel];
    
       
 
    
    
}

- (void)setModel:(CeShiModelOfFriendMessage *)model
{
    // 好友标签
    self.myMarkArray = [NSMutableArray arrayWithArray: [model valueForKey:@"mark"]];
    if (self.myMarkArray.count < 2) {
        CGFloat tempX = 0.0;
        // 标签
        for (int i = 0; i < self.myMarkArray.count; i++) {
            
            // 进行标签的动态布局
            UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xingMingLabel.left + tempX , self.xingMingLabel.bottom + 4 * kAdjustParamater, 50, 19 * kAdjustParamater)];
            tempLabel.font = [UIFont systemFontOfSize:11 * kAdjustParamater];
            // 取出内容
            tempLabel.text = self.myMarkArray[i];
            tempLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
            tempLabel.textAlignment = NSTextAlignmentCenter;
            CGRect tempRect = tempLabel.frame;
            tempRect.size.width   = [[NetStatusHandle shareHandle] adjustWidth:tempLabel.text size:11 height:19] + 10 * kAdjustParamater;
            tempLabel.frame = tempRect;
            tempX = tempLabel.frame.size.width + 5 * kAdjustParamater + tempX;
            // 添加边框
            [tempLabel.layer setBorderWidth:1];
            tempLabel.layer.borderColor = [[UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1] CGColor];
            [self.contentView addSubview:tempLabel];
        }
        
    } else {
        CGFloat tempX = 0.0;
        // 标签
        for (int i = 0; i < self.myMarkArray.count; i++) {
            
            // 进行标签的动态布局
            UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xingMingLabel.left + tempX , self.xingMingLabel.bottom + 4 * kAdjustParamater, 50, 19 * kAdjustParamater)];
            tempLabel.font = [UIFont systemFontOfSize:11 * kAdjustParamater];
            // 取出内容
            tempLabel.text = self.myMarkArray[i];
            tempLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
            tempLabel.textAlignment = NSTextAlignmentCenter;
            CGRect tempRect = tempLabel.frame;
            tempRect.size.width   = [[NetStatusHandle shareHandle] adjustWidth:tempLabel.text size:11 height:19] + 10 * kAdjustParamater;
            tempLabel.frame = tempRect;
            tempX = tempLabel.frame.size.width + 5 * kAdjustParamater + tempX;
            // 添加边框
            [tempLabel.layer setBorderWidth:1];
            tempLabel.layer.borderColor = [[UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1] CGColor];
            [self.contentView addSubview:tempLabel];
        }
        
    }
    // 名字
    self.nameLabel.text = model.name;
    CGRect newRect = self.nameLabel.frame;
    newRect.size.width = [[NetStatusHandle shareHandle] adjustWidth:self.nameLabel.text size:12 height:11];
    self.nameLabel.frame = newRect;
    // 性别图标
    self.genderImageView.frame = CGRectMake(self.nameLabel.right + 8 * kAdjustParamater, self.genderImageView.frame.origin.y, self.genderImageView.frame.size.width, self.genderImageView.frame.size.height);
    // ID
    self.IDLabel.text = model.myID;
    
    // 性别
    if ([model.gender isEqualToString:@"男"]) {
        self.genderImageView.image = [UIImage imageNamed:@"nan-tianjia"];
    } else {
        self.genderImageView.image = [UIImage imageNamed:@"nv-tianjia"];
    }
    
    // 好友头像
    self.friendImageV.image = [UIImage imageNamed:model.friendImage];
    
}


@end
